VERSION 5.00
Begin VB.Form frmJumlah2 
   BackColor       =   &H00404040&
   Caption         =   "Latihan VB"
   ClientHeight    =   3600
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   7305
   LinkTopic       =   "Form1"
   ScaleHeight     =   3600
   ScaleWidth      =   7305
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdKembali 
      Caption         =   "Kembali"
      Height          =   495
      Left            =   5160
      TabIndex        =   8
      Top             =   2760
      Width           =   1215
   End
   Begin VB.CommandButton cmdJumlah 
      Caption         =   "="
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   4440
      TabIndex        =   4
      Top             =   1320
      Width           =   495
   End
   Begin VB.CommandButton cmdHapus 
      Caption         =   "Hapus"
      Height          =   495
      Left            =   2040
      TabIndex        =   3
      Top             =   2760
      Width           =   1335
   End
   Begin VB.TextBox Text2 
      Alignment       =   1  'Right Justify
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2760
      TabIndex        =   2
      ToolTipText     =   "Silahkan isi, kemudian tekan enter"
      Top             =   1320
      Width           =   1335
   End
   Begin VB.TextBox Text3 
      Alignment       =   1  'Right Justify
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   5160
      Locked          =   -1  'True
      MousePointer    =   12  'No Drop
      TabIndex        =   1
      ToolTipText     =   "lock = true"
      Top             =   1320
      Width           =   1575
   End
   Begin VB.TextBox Text1 
      Alignment       =   1  'Right Justify
      Height          =   375
      Left            =   720
      TabIndex        =   0
      ToolTipText     =   "Silahkan isi, kemudian tekan enter"
      Top             =   1320
      Width           =   1335
   End
   Begin VB.Label Label3 
      Alignment       =   2  'Center
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "(Lanjutan)"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000FF00&
      Height          =   240
      Left            =   3270
      TabIndex        =   7
      Top             =   720
      Width           =   885
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      BackStyle       =   0  'Transparent
      Caption         =   "CONTOH PENGGUNAAN FUNGSI PENJUMLAHAN"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000FF00&
      Height          =   375
      Left            =   480
      TabIndex        =   6
      Top             =   240
      Width           =   6495
   End
   Begin VB.Label Label2 
      Alignment       =   2  'Center
      BackStyle       =   0  'Transparent
      Caption         =   "+"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FFFFFF&
      Height          =   375
      Index           =   0
      Left            =   2280
      TabIndex        =   5
      Top             =   1320
      Width           =   255
   End
End
Attribute VB_Name = "frmJumlah2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim input1 As Long
Dim input2 As Long
Dim hasil As Long

Private Sub cmdJumlah_Click()
'cek jika user telah mengisi input
If Text1.Text = "" Or Text2.Text = "" Then
 MsgBox "Ma'af, Isi dulu angkanya!"
 Text1.SetFocus
 Exit Sub
End If
'mengambil data dari user
'pada code dibawah ini digunakan fungsi "replace" karena
'teks pada text1 dan text2 menggunakan Format "###,##0"
'ingat, koma pada vb dibaca titik pada format angka indonesia
 input1 = Val(Replace(Text1.Text, ".", ""))
 input2 = Val(Replace(Text2.Text, ".", ""))
 'menghitung hasil
 hasil = input1 + input2
 'menampilkan hasil pada text3
 Text3.Text = hasil
 Text3.Refresh  'untuk memastikan tampilan
End Sub

Private Sub cmdHapus_Click()
 Text1.Text = ""
 Text2.Text = ""
 Text3.Text = ""
 'tempatakan kursor pada text1
 Text1.SetFocus
End Sub

Private Sub cmdKembali_Click()
 Load frmJumlah
 frmJumlah.Show
 Unload Me
End Sub

Private Sub text1_KeyPress(KeyAscii As Integer)
'agar hanya angka yang boleh diketikkan
If Not ((KeyAscii > 47 And KeyAscii < 58) Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then
   KeyAscii = 0
   Text1.Text = ""
   Beep
    Else
    'agar jika di tekan enter, kursor berpindah ke text2
    If KeyAscii = vbKeyReturn Then Text2.SetFocus
  End If
End Sub

Private Sub text2_KeyPress(KeyAscii As Integer)
'agar hanya angka yang boleh diketikkan
If Not ((KeyAscii > 47 And KeyAscii < 58) Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then
   KeyAscii = 0
   Text2.Text = ""
   Beep
    Else
    'agar jika di tekan enter, cmdJumlah dieksekusi
    If KeyAscii = vbKeyReturn Then cmdJumlah_Click
  End If
End Sub

Private Sub text1_KeyUp(KeyCode As Integer, Shift As Integer)
   Text1.Text = Format(Text1.Text, "###,##0")
   Text1.SelStart = Len(Text1.Text)
End Sub

Private Sub text2_KeyUp(KeyCode As Integer, Shift As Integer)
   Text2.Text = Format(Text2.Text, "###,##0")
   Text2.SelStart = Len(Text2.Text)
End Sub

Private Sub Text3_Change()
 Text3.Text = Format(Text3.Text, "###,##0")
End Sub

